<template>
  <view >
    <view class="goodlist">
      <view v-for="(item,index) in goodslist" :key="index" @click="gotogoodsdetail(item)">
        <my-goods :goods="item"></my-goods>
      </view>
      
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        cashu:{
          query:'',
          cid:'',
          pagenum:1,
          pagesize:10,
        },
        jc:0,//节流阀
        total:0,
        goodslist:[],
        defualt:'/static/tabicon/img1.jpg'
      };
    },
    //过滤属性可以用|传值
    onLoad(option) {
      this.cashu.query=option.query || ''
      this.cashu.cid=option.cid || ''
      uni.$getlistdata([uni.url_t.goodslist,this.cashu]).then((res)=>{
        this.total=res.total
        this.goodslist=res.goods
      })
    },
    //触底函数
    onReachBottom() {
      //节流操作
      if(this.goodslist.length===this.jc) return
      this.jc=this.goodslist.length
      this.cashu.pagenum++
      uni.$getlistdata([uni.url_t.goodslist,this.cashu]).then((res)=>{
        this.goodslist=[...this.goodslist,...res.goods]
        this.total=res.total
        if(this.goodslist.length===res.total) this.jc=this.goodslist.length
      })
    
      
    },
    onPullDownRefresh() {
      this.cashu.pagenum=1
      this.jc=0
      this.goodslist=[]
      uni.$getlistdata([uni.url_t.goodslist,this.cashu]).then((res)=>{
        this.goodslist=res.goods
        //让下拉框回去
        uni.stopPullDownRefresh()
      })
      
      
      
    },
    //点击商品进入商品详情页
    methods:{
      gotogoodsdetail(item){
        uni.navigateTo({
          url:'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id
        })
      }
    }
  }
</script>

<style lang="scss">
  .goodlist{
    padding: 0 5px;
    
  }

</style>
